//封装axios请求
let base_url="https://api.ruojy.top/api";
class Axios {
  post(url, data) {
    return this.request("POST", url, data)
  }
  get(url) {
    return this.request("GET", url,null)
  }
  detete(url) {
    return this.request("DELETE", url, null)
  }
  request(method, url, data) {
    //异步操作执行成功后的回调函数和异步操作执行失败后的回调函数:
    return new Promise((resolve, reject) => {
      wx.request({
        url: base_url+url,
        method:method,
        data:data,
        header: {
          "content-type": 'application/json',//默认值
          "token": 'xiaoyu'
        },
        success(res) {
          console.log(res.data);//打印返回的数据
          resolve(res.data)
        },
        fail(err) {
          reject(err)
        }
      })
    })
  }
}
module.exports = new Axios();//将其暴露出去